import React, { Component } from 'react';
import { View, StyleSheet } from 'react-native';
import RCTDeviceEventEmitter from 'react-native/Libraries/EventEmitter/RCTDeviceEventEmitter';

export default class Tomato extends Component {
	constructor(props) {
		super(props);
		this.pageDidInitialedObserver;
		this.pageOnResumeObserver;
		this.onNewIntentObserver;
	}

	render() {
		return (
		  <View>
		  </View>
		);
	}

	/**
	 * @description: 页面生命周期-渲染初始化完成回调
	 */
	pageDidInitialed() { }
	/**
	 * @description: 页面生命周期-页面重新出现回调
	 */
	pageOnResume() { }
	pageOnNewIntent(result) { }

	componentDidMount() {
		this.pageDidInitialedObserver = RCTDeviceEventEmitter.addListener("pageDidInitialed_" + this.props.uniqueKey, () => {
			this.pageDidInitialed();
		});
		this.pageOnResumeObserver = RCTDeviceEventEmitter.addListener("pageOnResume_" + this.props.uniqueKey, () => {
			this.pageOnResume();
		});
		this.onNewIntentObserver = RCTDeviceEventEmitter.addListener("onNewIntent_" + this.props.uniqueKey, (body) => {
			this.pageOnNewIntent(body);
		});
	}

	componentWillUnmount() {
		this.pageDidInitialedObserver && this.pageDidInitialedObserver.remove();
		this.pageOnResumeObserver && this.pageOnResumeObserver.remove();
		this.onNewIntentObserver && this.onNewIntentObserver.remove();
	}
}
